package com.liang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liang.entity.CFile;
import com.liang.mapper.CFileMapper;
import com.liang.service.CFileService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @name: CFileServiceImpl
 * @author: 李昂
 * @date: 2020-12-25 17:07
 * @description：CFileServiceImpl
 * @update: 2020-12-25 17:07
 */
@Service
@CacheConfig(cacheNames = "CFileMapper")
public class CFileServiceImpl extends ServiceImpl<CFileMapper, CFile> implements CFileService {

    //添加文件信息
    @Override
    @CacheEvict(value = "file", allEntries = true)
    public boolean addFileMsg(CFile file) {
        return this.save(file);
    }

    //根据文件id删除文件
    @Override
    @CacheEvict(value = "file", allEntries = true)
    public boolean deleteFileMsg(int id) {
        return this.removeById(id);
    }

    //根据类型  查看文件信息
    @Override
    @Cacheable(value = "file")
    public List<CFile> getFileMsgs(String type) {
        LambdaQueryWrapper<CFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CFile::getFtype, type);
        return this.list(lambdaQueryWrapper);
    }
}
